// pages/device/changData/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js")
const wxCharts = require("../../../../utils/wxcharts.js"), 
commonJs = require("../../../../component/common.js")
import Toast from '../../../../component/vant/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalVolume:0,
    totalWeight:0,
    device_id:0,
    submitState:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id){
      this.data.device_id = parseInt(options.id);
    }
  },

  bindInput(e){
    var value = e.detail;
    var key = e.currentTarget.dataset.key;
    if(key == 'volume'){
      this.data.totalVolume = value;
    } else if(key == 'weight'){
      this.data.totalWeight = value;
    }
  },

  /**
   * 上报数据的 http请求
   */
  submitOp: function () {
    var that = this;
    fetchApi.httpPost('/device/range/changeData', {
      device_id : that.data.device_id,
      total_weight: that.data.totalWeight,
    }, function (res) {
      console.log("上报数据的响应数据", res)
      if (res.data.code == 0) {
        Toast.success(res.data.msg);
        wx.navigateBack({
          delta: -1
        })
      }else{
        Toast.fail(res.data.msg);
      }
    }, function (res) {
    })
  },


})